<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 定义多个变量并赋值（传统写法）：
        let a = 12,b = 13,c = 14;

        // ES6可以通过解构的方式（数组解构）：
        let [i,j,k] = [1,2,3]
        console.log("i = ",i);
        console.log("j = ",j);
        console.log("k = ",k);

        // 如果数组中的一个位置上是数组如何解构？
        let arr = [1,[2.1,2.2],3];
        [i,j,k] = arr;
        console.log("i = ",i); // 1
        console.log("j = ",j); // [2.1,2.2]
        console.log("k = ",k); // 3

        let [l,m] = j;
        console.log("l = ",l);  // 2.1
        console.log("m = ",m);  // 2.2

        let [a1,[a2,a3],a4] = arr;
        console.log("a1 = ",a1);  // 1
        console.log("a2 = ",a2);  // 2.1
        console.log("a3 = ",a3);  // 2.2
        console.log("a4 = ",a4);  // 3

        // 如果我只想获取arr的第3位数据？
        let [,,d] = arr;
        console.log("d = ",d); // 3

        // 如果指向获取数组的头和尾
        arr = [1,2,3,4,5,6,7,8,9,10];
        let [head,second,...tail] = arr;
        console.log("head = ",head);
        console.log("second = ",second);
        console.log("tail = ",tail);

        arr = [1,2];
        [head,second,a,b] = arr;
        console.log("head = ",head); // 1
        console.log("second = ",second); // 2
        console.log("a = ",a); // undefined
        console.log("b = ",b); // undefined

        [head,second,a,...tail] = arr;
        console.log("head = ",head); // 1
        console.log("second = ",second); // 2
        console.log("a = ",a); // undefined
        console.log("tail = ",tail); // []


    </script>
</body>
</html>